<script>
    function _showChildGroup($show) {
        $('.childs-group').removeClass('active');
        $('.childs-param').removeClass('active');
        $($show).addClass('active');
    }

    function _child($show) {
        $('.childs-param').removeClass('active');
        $($show).addClass('active');
    }

    function inValid()  {

    }

</script>

<style>
    div.active {
        display: block !important;
    }

    .tabs2.ui-tabs .ui-tabs-panel {
        display: inline-block;
        width: 100%;
    }

    div.childs-group {
        display: none;
    }

    div.childs-param {
        display: none;
    }

    .input-small {
        width: 15px;
    }
    a.icon-show{
        cursor: pointer;
    }
</style>
<?php $form=$this->beginWidget('CActiveForm'); ?>

<div class="clearfix">

    <div style="width: 300px; float: left; margin-right: 10px;">
        <table class="table table-bordered">
            <?php foreach ($groups as $group):?>
                <tr>
                    <td><?php echo $group->name;?></td>
                    <td>
                        <input class="input-small numeric" type="text" value="<?php echo $group->index;?>" name="ParamGroup[index][]"/> 
                        <input class="input-small" type="hidden" value="<?php echo $group->id;?>" name="ParamGroup[id][]" />
                    </td>
                    <td><a onclick="_showChildGroup('.show-param<?php echo $group->id;?>')" class="icon-th-list icon-show"></a></td>
                </tr>
                <?php endforeach?>
        </table>
    </div>

    <?php foreach ($params as $params):?>
        <div class="childs-group show-param<?php echo $params['id'];?>" style="width: 300px; margin-right: 10px; float: left">
            <table class="table table-bordered">
                <?php foreach ($params['param'] as $param):?>
                    <tr>
                        <td><?php echo $param['name'];?></td>
                        <td>
                            <input class="input-small numeric" type="text" value="<?php echo $param['index'];?>" name="Param[index][]" /> 
                            <input class="input-small" type="hidden" value="<?php echo $param['id'];?>" name="Param[id][]" />
                        </td>
                        <td><a href="<?php echo Yii::app()->createUrl('admin/param/update', array('id' => $param['id']))?>">Edit</a></td>

                        <td><?php $check_child = Param::model()->findAll('parent_id=:parent_id', array(':parent_id'=>$param['id']));
                            if($check_child):?>
                            <a onclick="_child('.child<?php echo $param['id'];?>')" class="icon-th-list icon-show"></a>
                            <?php endif?>
                        </td>
                    </tr>
                    <?php endforeach?>
            </table>
        </div>
        <?php endforeach?>

    <?php foreach ($childsall as $params):?>
        <?php foreach ($params['param'] as $param):?>
            <div class="childs-param child<?php echo $param['id'];?>"
                style="width: 300px; margin-right: 10px; float: left">
                <table class="table table-bordered">
                    <?php $childs = Param::model()->findAll('parent_id=:parent_id', array(':parent_id'=>$param['id']));
                        foreach ($childs as $child):?>
                        <tr>
                            <td><?php echo $child->name; ?></td>
                            <td>
                                <input class="input-small numeric" type="text" value="<?php echo $child['index'];?>" name="Param[index][]" /> 
                                <input class="input-small" type="hidden" value="<?php echo $child['id'];?>" name="Param[id][]" />
                            </td>
                            <td><a href="<?php echo Yii::app()->createUrl('admin/param/update', array('id' => $child['id']));?>">Edit </a>
                            </td>
                        </tr>
                        <?php endforeach?>
                </table>
            </div>
            <?php endforeach?>
        <?php endforeach?>
</div>
<div style="margin-top: 20px; text-align: center;">
    <button class="btn btn-danger" type="submit" name="changindex">Cập nhật</button>
</div>
<?php $this->endWidget(); ?>